package day2.test;

import day2.dao.IDeptDao;
import day2.dao.IEmpDao;
import day2.entity.Dept;
import day2.entity.Emp;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import util.Util;

public class Deom4 {
    SqlSession session;
    IDeptDao deptDao;
    IEmpDao empDao;
    @Before
    public void init(){
        session= Util.getSession();
        deptDao=session.getMapper(IDeptDao.class);
        empDao=session.getMapper(IEmpDao.class);
    }
    @After
    public void close(){
        session.commit();
        session.close();
    }
    @Test
    public void insertDept(){
        Dept d=new Dept();
        d.setName("财务");
        deptDao.insertDept(d);
    }
    @Test
    public void insertEmp(){
        Dept d=new Dept();
        d.setId(16);

        Emp e=new Emp();
        e.setName("a1");
        e.setSalary(1000d);
        e.setDept(d);
        empDao.insertEmp(e);
    }
    @Test
    public void selectAllEmp(){
        System.out.println(empDao.selectAllEmp());
    }
    @Test
    public void selectEmpByDeptId(){
        System.out.println(empDao.selectEmpByDeptId(15));
    }
    @Test
    public void selectDeptStep() throws InterruptedException {
        Dept d=deptDao.selectDeptByNameStep("d6");
        System.out.println(d.getName());
        Thread.sleep(5000);
        System.out.println(d.getEmps());
    }
}
